#include <iostream>
#include <string>
#include <map>
using namespace std;

class Product 
{
public:
	virtual ~Product() {}
	virtual void perform() = 0;
};

class ProductA: public Product 
{
public:
	void perform() 
    {
		cout << "create the product A" << endl;
	}
};

class ProductB: public Product 
{
public:
	void perform() 
    {
		cout << "create the product B" << endl;
	}
};

class ProductC: public Product 
{
public:
	void perform() 
    {
		cout << "create the product C" << endl;
	}
};

class Factory 
{
private:
    map<int, Product*> products;
	Factory() {}
    void init()
    {
        products[1] = new ProductA();
        products[2] = new ProductB();
        products[3] = new ProductC();
    }
public:
	static Factory* getInstance() 
	{
		static Factory* instance;
        if(instance==NULL)
        {
            instance = new Factory();
            instance->init();
        }
		return instance;
	}
	Product* create(int type) 
	{
        return products[type];
	}
};

int main() 
{
	Factory* factory = Factory::getInstance();
	int type = 1;
	Product* product = factory->create(type);
	product->perform();
	return 0;
}
